package com.example.autocall2;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class CallRecord {
    long date;
    String formatted_number;
    String matched_number;
    String name;
    String type;
    String location;
    long duration;

    @Override
    public String toString() {
        return "CallRecord{" +
                "date=" + formatDate(date) +
                ", formatted_number='" + formatted_number + '\'' +
                ", matched_number='" + matched_number + '\'' +
                ", name='" + name + '\'' +
                ", type=" + type +
                ", location='" + location + '\'' +
                ", duration=" + formatDuration(duration) +
                '}';
    }

    public String formatDate(long time) {
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.getDefault());
        return format.format(new Date(time));
    }
    public String formatDuration(long time) {
        long s = time % 60;
        long m = time / 60;
        long h = time / 60 / 60;
        StringBuilder sb = new StringBuilder();
        if (h > 0) {
            sb.append(h).append("小时");
        }
        if (m > 0) {
            sb.append(m).append("分");
        }
        sb.append(s).append("秒");
        return sb.toString();
    }
}